<?php
/**
 * Created by PhpStorm.
 * User: Administrator--Reer
 * Date: 2019/9/12 0012
 * Time: 9:52
 */

namespace app\admin\controller;

use app\common\bean\DistributionBean;
use app\common\bean\GlobalBean;
use app\common\bean\ListMap;
use app\common\controller\AdminController;
use app\common\manage\DistributionManage;
use app\common\model\DistributionModel;
use app\common\utils\ExitJsonUtil;

class Distribution extends AdminController
{
    public function del(){
        $distributionBean = new DistributionBean();
        $distributionBean->setData($this->getParams);
        DistributionManage::getInstance()->delete($distributionBean);
        ExitJsonUtil::getInstance()->exitData([]);
    }
    public function add(){
        $distributionBean = new DistributionBean();
        $distributionBean->setStoreId(0);
        DistributionManage::getInstance()->add($distributionBean);
    }
    public function index(){
        $listMap = new ListMap();
        $listMap->setData($this->getParams);
        $listMap->setParameter(DistributionBean::$storeId, 0);
        $list = DistributionManage::getInstance()->getPaginatorList($listMap);
        $this->assign([
            'list'=>$list->getList(),
        ]);
        return $this->fetch();
    }
    public function edit(){
        if(request()->post()){
            $post = $this->postParams;
            DistributionModel::getInstance()->updateColumn(DistributionBean::$id, $post[DistributionBean::$id], $post['field'], $post['value']);
            ExitJsonUtil::getInstance()->exitData([]);
        }
        $where[DistributionBean::$storeId] = 0;
        $list = DistributionModel::getInstance()->selectData($where, 1, [DistributionBean::$distance]);
        $this->assign(['list'=>$list]);
        return $this->fetch();
    }
}